#
# @lc app=leetcode.cn id=28 lang=python3
#
# [28] 实现 strStr()
#

# @lc code=start
class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        h, n = len(haystack), len(needle)
        if n == 0: return 0
        if h < n: return -1
        i = 0
        while 1:
            if i + n > h: return -1
            j = 0
            while 1:
                if j == n: return i
                if haystack[i + j] != needle[j]: break
                j += 1
            i += 1
            

# @lc code=end

